make shape a subclass of Format. (#512)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Mon, 24 Feb 2020 18:22:16 +0000 (11:22 -0700)
committerGitHub <noreply@github.com>
Mon, 24 Feb 2020 18:22:16 +0000 (11:22 -0700)
* make shape a subclass of Format.

* correct type of 2nd param passed to SHPCreateSimpleObject

CMakeLists.txt
GPSBabel.pro
Makefile.in
shape.cc
shape.h [new file with mode: 0644]
testo.d/serialization.test [changed mode: 0755->0644]
testo.d/shape.test [changed mode: 0755->0644]
vecs.h

index 356c20f442b8e9890a938ddf4a62b31dca675a5b..25807d25a0fdf95e9ac1a960a0b563b367a93f8d 100644 (file)
@@ -151,6 +151,7 @@ set(HEADERS
   mynav.h
   navilink.h
   session.h
+  shape.h
   shapelib/shapefil.h
   strptime.h
   units.h
index 9ea05dd279dda456e1efec71e97b24b9fa36d946..8f82a6389a0df26b64ecb10fc6ce7b56a06c507d 100644 (file)
@@ -139,6 +139,7 @@ HEADERS =  \
        mynav.h \
        navilink.h \
        session.h \
+       shape.h \
        shapelib/shapefil.h \
        strptime.h \
        units.h \
index 4981783b5055a578186bd9d4d219666cbe9a0457..f04c64080d7244ece4aa1f274184aecb65aebd9d 100644 (file)
@@ -511,11 +511,12 @@ filter_vecs.o: filter_vecs.cc defs.h config.h zlib/zlib.h zlib/zconf.h \
   position.h radius.h reverse_route.h smplrout.h sort.h stackfilter.h \
   swapdata.h trackfilter.h transform.h validate.h gbversion.h vecs.h \
   format.h ggv_bin.h gpx.h src/core/file.h src/core/xmlstreamwriter.h \
-  src/core/xmltag.h legacyformat.h mynav.h xcsv.h garmin_fs.h \
-  jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h jeeps/gpsdevice.h \
-  jeeps/gpssend.h jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h \
-  jeeps/gpsprot.h jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h \
-  jeeps/gpsmem.h jeeps/gpsrqst.h src/core/textstream.h
+  src/core/xmltag.h shape.h shapelib/shapefil.h yahoo.h xmlgeneric.h \
+  legacyformat.h mynav.h xcsv.h garmin_fs.h jeeps/gps.h jeeps/../defs.h \
+  jeeps/gpsport.h jeeps/gpsdevice.h jeeps/gpssend.h jeeps/gpsread.h \
+  jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h jeeps/gpscom.h \
+  jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h jeeps/gpsrqst.h \
+  src/core/textstream.h
 formspec.o: formspec.cc defs.h config.h zlib/zlib.h zlib/zconf.h \
   formspec.h inifile.h gbfile.h session.h src/core/datetime.h \
   src/core/optional.h
@@ -534,7 +535,8 @@ garmin.o: garmin.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
   jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h \
   jeeps/gpsrqst.h garmin_tables.h grtcirc.h jeeps/gpsserial.h vecs.h \
   ggv_bin.h gpx.h src/core/file.h src/core/xmlstreamwriter.h \
-  src/core/xmltag.h legacyformat.h mynav.h xcsv.h src/core/textstream.h
+  src/core/xmltag.h shape.h shapelib/shapefil.h yahoo.h xmlgeneric.h \
+  legacyformat.h mynav.h xcsv.h src/core/textstream.h
 garmin_device_xml.o: garmin_device_xml.cc defs.h config.h zlib/zlib.h \
   zlib/zconf.h formspec.h inifile.h gbfile.h session.h \
   src/core/datetime.h src/core/optional.h garmin_device_xml.h \
@@ -677,7 +679,8 @@ internal_styles.o: internal_styles.cc defs.h config.h zlib/zlib.h \
   src/core/datetime.h src/core/optional.h
 interpolate.o: interpolate.cc defs.h config.h zlib/zlib.h zlib/zconf.h \
   formspec.h inifile.h gbfile.h session.h src/core/datetime.h \
-  src/core/optional.h interpolate.h filter.h grtcirc.h
+  src/core/optional.h interpolate.h filter.h grtcirc.h \
+  src/core/logging.h
 itracku.o: itracku.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
   inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \
   gbser.h
@@ -814,11 +817,12 @@ magproto.o: magproto.cc defs.h config.h zlib/zlib.h zlib/zconf.h \
   formspec.h inifile.h gbfile.h session.h src/core/datetime.h \
   src/core/optional.h explorist_ini.h format.h gbser.h magellan.h vecs.h \
   ggv_bin.h gpx.h src/core/file.h src/core/xmlstreamwriter.h \
-  src/core/xmltag.h legacyformat.h mynav.h xcsv.h garmin_fs.h \
-  jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h jeeps/gpsdevice.h \
-  jeeps/gpssend.h jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h \
-  jeeps/gpsprot.h jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h \
-  jeeps/gpsmem.h jeeps/gpsrqst.h src/core/textstream.h
+  src/core/xmltag.h shape.h shapelib/shapefil.h yahoo.h xmlgeneric.h \
+  legacyformat.h mynav.h xcsv.h garmin_fs.h jeeps/gps.h jeeps/../defs.h \
+  jeeps/gpsport.h jeeps/gpsdevice.h jeeps/gpssend.h jeeps/gpsread.h \
+  jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h jeeps/gpscom.h \
+  jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h jeeps/gpsrqst.h \
+  src/core/textstream.h
 main.o: main.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
   inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \
   cet_util.h csv_util.h filter.h filter_vecs.h arcdist.h bend.h \
@@ -826,8 +830,9 @@ main.o: main.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
   polygon.h position.h radius.h reverse_route.h smplrout.h sort.h \
   stackfilter.h swapdata.h trackfilter.h transform.h validate.h format.h \
   src/core/file.h src/core/usasciicodec.h vecs.h ggv_bin.h gpx.h \
-  src/core/xmlstreamwriter.h src/core/xmltag.h legacyformat.h mynav.h \
-  xcsv.h garmin_fs.h jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h \
+  src/core/xmlstreamwriter.h src/core/xmltag.h shape.h \
+  shapelib/shapefil.h yahoo.h xmlgeneric.h legacyformat.h mynav.h xcsv.h \
+  garmin_fs.h jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h \
   jeeps/gpsdevice.h jeeps/gpssend.h jeeps/gpsread.h jeeps/gpsutil.h \
   jeeps/gpsapp.h jeeps/gpsprot.h jeeps/gpscom.h jeeps/gpsfmt.h \
   jeeps/gpsmath.h jeeps/gpsmem.h jeeps/gpsrqst.h src/core/textstream.h
@@ -949,7 +954,7 @@ session.o: session.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
   inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h
 shape.o: shape.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
   inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \
-  shapelib/shapefil.h
+  shape.h format.h shapelib/shapefil.h
 shapelib/dbfopen.o: shapelib/dbfopen.c shapelib/shapefil.h
 shapelib/safileio.o: shapelib/safileio.c shapelib/shapefil.h
 shapelib/shpopen.o: shapelib/shpopen.c shapelib/shapefil.h
@@ -1042,8 +1047,9 @@ vcf.o: vcf.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
 vecs.o: vecs.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
   inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \
   vecs.h format.h ggv_bin.h gpx.h src/core/file.h \
-  src/core/xmlstreamwriter.h src/core/xmltag.h legacyformat.h mynav.h \
-  xcsv.h garmin_fs.h jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h \
+  src/core/xmlstreamwriter.h src/core/xmltag.h shape.h \
+  shapelib/shapefil.h yahoo.h xmlgeneric.h legacyformat.h mynav.h xcsv.h \
+  garmin_fs.h jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h \
   jeeps/gpsdevice.h jeeps/gpssend.h jeeps/gpsread.h jeeps/gpsutil.h \
   jeeps/gpsapp.h jeeps/gpsprot.h jeeps/gpscom.h jeeps/gpsfmt.h \
   jeeps/gpsmath.h jeeps/gpsmem.h jeeps/gpsrqst.h src/core/textstream.h \
@@ -1091,9 +1097,9 @@ xol.o: xol.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
   inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \
   garmin_tables.h jeeps/gpsmath.h jeeps/gpsport.h src/core/file.h \
   src/core/xmlstreamwriter.h xmlgeneric.h
-yahoo.o: yahoo.cc defs.h config.h zlib/zlib.h zlib/zconf.h config.h \
formspec.h inifile.h gbfile.h session.h src/core/datetime.h \
src/core/optional.h yahoo.h format.h xmlgeneric.h
+yahoo.o: yahoo.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
 inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \
+  yahoo.h format.h xmlgeneric.h
 zlib/adler32.o: zlib/adler32.c zlib/zutil.h zlib/zlib.h zlib/zconf.h \
   config.h
 zlib/compress.o: zlib/compress.c zlib/zlib.h zlib/zconf.h config.h
index 7e95979f3e3270bd3248a8b1b3d1f657fd3e2634..933eb95a4d0af282998331c3db1c41d856c29b97 100644 (file)
--- a/shape.cc
+++ b/shape.cc
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
  */
-#include <QtCore/QLatin1String>
-#include <QtCore/QString>
-#include <QtCore/QStringList>
-#include <QtCore/QVector>
+
+#include <assert.h>              // for assert
+
+#include <QtCore/QByteArray>     // for QByteArray
+#include <QtCore/QLatin1String>  // for QLatin1String
+#include <QtCore/QString>        // for QString, QString::SkipEmptyParts
+#include <QtCore/QStringList>    // for QStringList
+#include <QtCore/QVector>        // for QVector
+#include <QtCore/Qt>             // for CaseInsensitive
+#include <QtCore/QtGlobal>       // for qPrintable
 
 #include "defs.h"
+#include "shape.h"
 #include "shapelib/shapefil.h"
-#include <cstdlib>
+
 
 #if SHAPELIB_ENABLED
-static SHPHandle ihandle;
-static DBFHandle ihandledb;
-static SHPHandle ohandle;
-static DBFHandle ohandledb;
 #define MYNAME "shape"
 
-static unsigned poly_count;
-static double* polybufx;
-static double* polybufy;
-static double* polybufz;
-static QString ifname;
-static QString ofname;
-static int nameFieldIdx;       // the field index of the field with fieldName "name" in the output DBF.
-
-static char* opt_name = nullptr;
-static char* opt_url = nullptr;
-
-static
-QVector<arglist_t> shp_args = {
-  {
-    "name", &opt_name, "Source for name field in .dbf",
-    nullptr, ARGTYPE_STRING, "0", nullptr, nullptr
-  },
-  {
-    "url", &opt_url, "Source for URL field in .dbf",
-    nullptr, ARGTYPE_STRING, "0", nullptr, nullptr
-  },
-};
-
-
 /************************************************************************/
 /*                              SHPOpenGpsbabel()                       */
 /************************************************************************/
 
-static SHPHandle SHPAPI_CALL
-SHPOpenGpsbabel(const QString& pszLayer, const char* pszAccess)
+SHPHandle SHPAPI_CALL
+ShapeFormat::SHPOpenGpsbabel(const QString& pszLayer, const char* pszAccess)
 
 {
   SAHooks sHooks;
@@ -86,8 +65,8 @@ SHPOpenGpsbabel(const QString& pszLayer, const char* pszAccess)
 /*      shape file with read/write access.                              */
 /************************************************************************/
 
-static SHPHandle SHPAPI_CALL
-SHPCreateGpsbabel(const QString& pszLayer, int nShapeType)
+SHPHandle SHPAPI_CALL
+ShapeFormat::SHPCreateGpsbabel(const QString& pszLayer, int nShapeType)
 
 {
   SAHooks sHooks;
@@ -108,8 +87,8 @@ SHPCreateGpsbabel(const QString& pszLayer, int nShapeType)
 /*      Open a .dbf file.                                               */
 /************************************************************************/
 
-static DBFHandle SHPAPI_CALL
-DBFOpenGpsbabel(const QString& pszFilename, const char* pszAccess)
+DBFHandle SHPAPI_CALL
+ShapeFormat::DBFOpenGpsbabel(const QString& pszFilename, const char* pszAccess)
 
 {
   SAHooks sHooks;
@@ -130,18 +109,18 @@ DBFOpenGpsbabel(const QString& pszFilename, const char* pszAccess)
 /*      Create a new .dbf file.                                         */
 /************************************************************************/
 
-static DBFHandle SHPAPI_CALL
-DBFCreateExGpsbabel(const QString& pszFilename, const char* pszCodePage)
+DBFHandle SHPAPI_CALL
+ShapeFormat::DBFCreateExGpsbabel(const QString& pszFilename, const char* pszCodePage)
 
 {
   SAHooks sHooks;
 
 #ifdef SHPAPI_UTF8_HOOKS
   SASetupUtf8Hooks(&sHooks);
-  return DBFCreateLL(pszFilename.toUtf8().constData(), pszCodePage , &sHooks);
+  return DBFCreateLL(pszFilename.toUtf8().constData(), pszCodePage, &sHooks);
 #else
   SASetupDefaultHooks(&sHooks);
-  return DBFCreateLL(qPrintable(pszFilename), pszCodePage , &sHooks);
+  return DBFCreateLL(qPrintable(pszFilename), pszCodePage, &sHooks);
 #endif
 
 }
@@ -153,16 +132,15 @@ DBFCreateExGpsbabel(const QString& pszFilename, const char* pszCodePage)
 /* Create a new .dbf file with default code page LDID/87 (0x57)         */
 /************************************************************************/
 
-static DBFHandle SHPAPI_CALL
-DBFCreateGpsbabel(const QString& pszFilename)
+DBFHandle SHPAPI_CALL
+ShapeFormat::DBFCreateGpsbabel(const QString& pszFilename)
 
 {
   return DBFCreateExGpsbabel(pszFilename, "LDID/87");   // 0x57
 }
 #endif
 
-static
-void dump_fields()
+void ShapeFormat::dump_fields() const
 {
   char name[12];
   warning(MYNAME ": Database fields:\n");
@@ -174,8 +152,7 @@ void dump_fields()
   fatal("\n");
 }
 
-static
-void check_field_index(const int fieldIdx)
+void ShapeFormat::check_field_index(const int fieldIdx) const
 {
   const int maxFields = DBFGetFieldCount(ihandledb);
   if (fieldIdx < 0 || fieldIdx >= maxFields) {
@@ -185,8 +162,7 @@ void check_field_index(const int fieldIdx)
   }
 }
 
-static
-int get_field_index(const QString& fieldName)
+int ShapeFormat::get_field_index(const QString& fieldName) const
 {
   const int fieldIdx = DBFGetFieldIndex(ihandledb, CSTR(fieldName));
   if (fieldIdx < 0) {
@@ -196,8 +172,8 @@ int get_field_index(const QString& fieldName)
   return fieldIdx;
 }
 
-static void
-my_rd_init(const QString& fname)
+void
+ShapeFormat::rd_init(const QString& fname)
 {
   ifname = fname;
   // TODO: The .prj file can define the the coordinate system and projection information.
@@ -221,10 +197,10 @@ my_rd_init(const QString& fname)
   }
 }
 
-static void
-my_read()
+void
+ShapeFormat::read()
 {
-  // option processing here instead of in my_rd_init
+  // option processing here instead of in rd_init
   // lets the results of option processing be automatic.
   int nameidx;
   int urlidx;
@@ -396,58 +372,58 @@ err:
 
 }
 
-static void
-my_rd_deinit()
+void
+ShapeFormat::rd_deinit()
 {
   SHPClose(ihandle);
   DBFClose(ihandledb);
   ifname.clear();
 }
 
-static void
-my_wr_init(const QString& fname)
+void
+ShapeFormat::wr_init(const QString& fname)
 {
   ofname = fname;
 }
 
-static void
-my_wr_deinit()
+void
+ShapeFormat::wr_deinit()
 {
   SHPClose(ohandle);
   DBFClose(ohandledb);
   ofname.clear();
 }
 
-static void
-my_write_wpt(const Waypoint* wpt)
+void
+ShapeFormat::write_wpt(const Waypoint* wpt) const
 {
   // note that the z coordinate (&wpt->altitude) does not apply
   // to SHPT_POINT.
   // We could potentially write SHPT_POINTZ, but we would have
   // to address what to do when we don't have altitude data.
   SHPObject* shpobject = SHPCreateSimpleObject(SHPT_POINT, 1,
-                                                &wpt->longitude,
-                                                &wpt->latitude,
-                                                &wpt->altitude);
+                         &wpt->longitude,
+                         &wpt->latitude,
+                         &wpt->altitude);
   int iShape = SHPWriteObject(ohandle, -1, shpobject);
   SHPDestroyObject(shpobject);
   DBFWriteStringAttribute(ohandledb, iShape, nameFieldIdx,
                           CSTR(wpt->shortname));
 }
 
-static void
-poly_init(const route_head* rte)
+void
+ShapeFormat::poly_init(const route_head* rte)
 {
   const int ct = rte->rte_waypt_ct;
   poly_count = 0;
-  polybufx = (double*) xcalloc(ct, sizeof(double));
-  polybufy = (double*) xcalloc(ct, sizeof(double));
-  polybufz = (double*) xcalloc(ct, sizeof(double));
+  polybufx = new double[ct];
+  polybufy = new double[ct];
+  polybufz = new double[ct];
 }
 
 
-static void
-poly_point(const Waypoint* wpt)
+void
+ShapeFormat::poly_point(const Waypoint* wpt)
 {
   polybufx[poly_count] = wpt->longitude;
   polybufy[poly_count] = wpt->latitude;
@@ -455,28 +431,29 @@ poly_point(const Waypoint* wpt)
   poly_count++;
 }
 
-static void
-poly_deinit(const route_head* rte)
+void
+ShapeFormat::poly_deinit(const route_head* rte)
 {
   // note that the z coordinate (polybufz) does not apply
   // to SHPT_ARC.
   // We could potentially write SHPT_ARCZ, but we would have
   // to address what to do when we don't have altitude data.
+  assert(rte->rte_waypt_ct == poly_count);
   SHPObject* shpobject = SHPCreateSimpleObject(SHPT_ARC, poly_count,
-                                                polybufx, polybufy, polybufz);
+                         polybufx, polybufy, polybufz);
   int iShape = SHPWriteObject(ohandle, -1,  shpobject);
   SHPDestroyObject(shpobject);
   DBFWriteStringAttribute(ohandledb, iShape, nameFieldIdx,
                           CSTR(rte->rte_name));
-  xfree(polybufx);
-  xfree(polybufy);
-  xfree(polybufz);
+  delete[] polybufx;
+  delete[] polybufy;
+  delete[] polybufz;
   poly_count = 0;
 }
 
 
-static void
-my_write()
+void
+ShapeFormat::write()
 {
   // shape files can only contain one shape type in addition
   // to the null shape type.
@@ -484,7 +461,7 @@ my_write()
   // route/track data.
   switch (global_opts.objective) {
   case wptdata:
-  case unknown_gpsdata:
+  case unknown_gpsdata: {
     ohandle = SHPCreateGpsbabel(ofname, SHPT_POINT);
 
     if (ohandle == nullptr) {
@@ -497,10 +474,14 @@ my_write()
             qPrintable(ofname));
     }
     nameFieldIdx=DBFAddField(ohandledb,"name",FTString,100,0);
-    waypt_disp_all(my_write_wpt);
+    auto write_wpt_lambda = [this](const Waypoint* wpt)->void {
+      write_wpt(wpt);
+    };
+    waypt_disp_all(write_wpt_lambda);
     break;
+  }
   case rtedata:
-  case trkdata:
+  case trkdata: {
     ohandle = SHPCreateGpsbabel(ofname, SHPT_ARC);
 
     if (ohandle == nullptr) {
@@ -513,31 +494,25 @@ my_write()
             qPrintable(ofname));
     }
     nameFieldIdx=DBFAddField(ohandledb,"name",FTString,100,0);
+    auto poly_init_lambda = [this](const route_head* rte)->void {
+      poly_init(rte);
+    };
+    auto poly_deinit_lambda = [this](const route_head* rte)->void {
+      poly_deinit(rte);
+    };
+    auto poly_point_lambda = [this](const Waypoint* wpt)->void {
+      poly_point(wpt);
+    };
     if (global_opts.objective == trkdata) {
-      track_disp_all(poly_init, poly_deinit, poly_point);
+      track_disp_all(poly_init_lambda, poly_deinit_lambda, poly_point_lambda);
     } else { // rtedata
-      route_disp_all(poly_init, poly_deinit, poly_point);
+      route_disp_all(poly_init_lambda, poly_deinit_lambda, poly_point_lambda);
     }
     break;
+  }
   case posndata:
     fatal(MYNAME ": Realtime positioning not supported\n");
     break;
   }
 }
-
-ff_vecs_t shape_vecs = {
-  ff_type_file,
-  FF_CAP_RW_ALL,
-  my_rd_init,
-  my_wr_init,
-  my_rd_deinit,
-  my_wr_deinit,
-  my_read,
-  my_write,
-  nullptr,
-  &shp_args,
-  CET_CHARSET_ASCII, 0 /* CET-REVIEW */
-  , NULL_POS_OPS,
-  nullptr
-};
 #endif /* SHAPELIB_ENABLED */
diff --git a/shape.h b/shape.h
new file mode 100644 (file)
index 0000000..75ec82c
--- /dev/null
+++ b/shape.h
@@ -0,0 +1,110 @@
+/*
+
+    ESRI shp/shx shapefiles.
+
+    Copyright (C) 2003 Robert Lipe, robertlipe+source@gpsbabel.org
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+ */
+#ifndef SHAPE_H_INCLUDED_
+#define SHAPE_H_INCLUDED_
+
+#include <QtCore/QString>       // for QString
+#include <QtCore/QVector>       // for QVector
+
+#include "defs.h"               // for arglist_t, ARGTYPE_STRING, Waypoint, route_head, CET_CHARSET_ASCII, FF_CAP_RW_ALL, ff_cap, ff_type, ff_type_file
+#include "format.h"             // for Format
+#include "shapelib/shapefil.h"  // for DBFHandle, SHPAPI_CALL, SHPHandle
+
+
+#if SHAPELIB_ENABLED
+class ShapeFormat : public Format
+{
+public:
+  QVector<arglist_t>* get_args() override
+  {
+    return &shp_args;
+  }
+
+  ff_type get_type() const override
+  {
+    return ff_type_file;
+  }
+
+  QVector<ff_cap> get_cap() const override
+  {
+    return FF_CAP_RW_ALL;
+  }
+
+  QString get_encode() const override
+  {
+    return CET_CHARSET_ASCII;
+  }
+
+  int get_fixed_encode() const override
+  {
+    return 0;
+  }
+
+  void rd_init(const QString& fname) override;
+  void read() override;
+  void rd_deinit() override;
+  void wr_init(const QString& fname) override;
+  void write() override;
+  void wr_deinit() override;
+
+private:
+  static SHPHandle SHPAPI_CALL SHPOpenGpsbabel(const QString& pszLayer, const char* pszAccess);
+  static SHPHandle SHPAPI_CALL SHPCreateGpsbabel(const QString& pszLayer, int nShapeType);
+  static DBFHandle SHPAPI_CALL DBFOpenGpsbabel(const QString& pszFilename, const char* pszAccess);
+  static DBFHandle SHPAPI_CALL DBFCreateExGpsbabel(const QString& pszFilename, const char* pszCodePage);
+  void dump_fields() const;
+  void check_field_index(int fieldIdx) const;
+  int get_field_index(const QString& fieldName) const;
+  void write_wpt(const Waypoint* wpt) const;
+  void poly_init(const route_head* rte);
+  void poly_point(const Waypoint* wpt);
+  void poly_deinit(const route_head* rte);
+
+  SHPHandle ihandle;
+  DBFHandle ihandledb;
+  SHPHandle ohandle;
+  DBFHandle ohandledb;
+
+  int poly_count;
+  double* polybufx;
+  double* polybufy;
+  double* polybufz;
+  QString ifname;
+  QString ofname;
+  int nameFieldIdx;    // the field index of the field with fieldName "name" in the output DBF.
+
+  char* opt_name = nullptr;
+  char* opt_url = nullptr;
+
+  QVector<arglist_t> shp_args = {
+    {
+      "name", &opt_name, "Source for name field in .dbf",
+      nullptr, ARGTYPE_STRING, "0", nullptr, nullptr
+    },
+    {
+      "url", &opt_url, "Source for URL field in .dbf",
+      nullptr, ARGTYPE_STRING, "0", nullptr, nullptr
+    },
+  };
+#endif /* SHAPELIB_ENABLED */
+};
+#endif // SHAPE_H_INCLUDED_
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
diff --git a/vecs.h b/vecs.h
index ee5a082c0905cdd6fba7a24053250a00f403d3ee..9e5719fa62ee0e18ec7ee9cb6c227ee7a220867f 100644 (file)
--- a/vecs.h
+++ b/vecs.h
 #include "format.h"
 #include "ggv_bin.h"
 #include "gpx.h"
-#include "yahoo.h"
 #include "legacyformat.h"
 #include "mynav.h"
+#include "shape.h"
 #include "xcsv.h"
+#include "yahoo.h"
 
 
 extern ff_vecs_t geo_vecs;
@@ -62,9 +63,6 @@ extern ff_vecs_t easygps_vecs;
 extern ff_vecs_t saroute_vecs;
 extern ff_vecs_t navicache_vecs;
 extern ff_vecs_t psit_vecs;
-#if SHAPELIB_ENABLED
-extern ff_vecs_t shape_vecs;
-#endif
 extern ff_vecs_t gpl_vecs;
 extern ff_vecs_t text_vecs;
 extern ff_vecs_t html_vecs;
@@ -296,7 +294,7 @@ private:
   LegacyFormat navicache_fmt {navicache_vecs};
   LegacyFormat psit_fmt {psit_vecs};
 #if SHAPELIB_ENABLED
-  LegacyFormat shape_fmt {shape_vecs};
+  ShapeFormat shape_fmt;
 #endif
   LegacyFormat gpl_fmt {gpl_vecs};
   LegacyFormat text_fmt {text_vecs};